package com.link2room.rodimus.controller.api;

import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.result.base.BaseSession;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.util.StringUtil;
import com.link2room.rodimus.dto.param.api.ModifyCurrentUserMemberNameParamDto;
import com.link2room.rodimus.dto.param.api.RodimusBindingApiParamDto;
import com.link2room.rodimus.dto.param.api.UsableCouopnsApiParamDto;
import com.link2room.rodimus.dto.param.base.RodimusLoginBaseParamDto;
import com.link2room.rodimus.facade.IMemberApiFacadeService;
import com.link2room.soundwave.dto.result.base.PmsCouponDto;
import com.link2room.soundwave.dto.result.base.PmsMemberPointDto;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Optional;

/**
 * Created by VegetaKo on 2016/9/14.
 */
@Api(tags = "会员相关")
@RestController
@RequestMapping("/api/MemberNew/Members")
public class MemberInfoApiControllerRemoveTicket {

    @Resource
    private IMemberApiFacadeService memberApiFacadeService;

    @RequestMapping(method = RequestMethod.POST)
    public BaseResultDto newMemberInfo(
            @RequestBody RodimusLoginBaseParamDto rodimusLoginBaseParamDto
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        memberApiFacadeService.wxNewMember(rodimusLoginBaseParamDto);
        res.setResultCode(0);
        return res;
    }
    @RequestMapping(method = RequestMethod.GET)
    public  BaseResultDto getMemberInfo()throws Exception{
        RodimusLoginBaseParamDto rodimusLoginBaseParamDto = new RodimusLoginBaseParamDto();
        BaseSession session =memberApiFacadeService.getMember(rodimusLoginBaseParamDto);
        //BaseSession session =   aerAuthFacadeService.getSession(rodimusLoginBaseParamDto);
        BaseResultDto res =new BaseResultDto();
        res.setResultCode(0);
        res.setResultInfo(session);
        return res;
    }

    @RequestMapping(value = "/Pmsmember",method = RequestMethod.POST)
    public BaseResultDto bindingPMSMember(
            @RequestBody RodimusBindingApiParamDto rodimusBindingApiParamDto
    ) throws Exception {
        BaseResultDto res  = new BaseResultDto();
        memberApiFacadeService.bindingPMSMember(rodimusBindingApiParamDto);
        res.setResultCode(0);
        return res;
    }

    /**
     * pmsmemberinfo
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/Pmsmember",method = RequestMethod.GET)
    public BaseResultDto getPMSMember(
    ) throws Exception {
        BaseResultDto  baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(memberApiFacadeService.getPMSMemberInfo());
        return baseResultDto;
    }

    /**
     * 根据ticket获取积分信息
     * @return
     */
    @RequestMapping(value = "/Points",method = RequestMethod.GET)
    public BaseResultDto getPoints(
    )throws Exception {
        PmsMemberPointDto memberPointDto =   memberApiFacadeService.getPMSmemberPoints(new RodimusLoginBaseParamDto());
        BaseResultDto res =new BaseResultDto();
        res.setResultCode(0);
        res.setResultInfo(memberPointDto);
        return res;
    }

    /**
     * 根据ticket获取积分详情
     * @param ticket
     * @return
     */
    @RequestMapping(value = "/PointsDetail",method = RequestMethod.GET)
    public BaseResultDto getPointsDetail(
            @PathVariable String ticket
    )throws Exception {
        BaseResultDto res =new BaseResultDto();
        res.setResultCode(0);
        res.setQueryResult(memberApiFacadeService.getPMSmemberPointsDetail(new RodimusLoginBaseParamDto()));
        return res;
    }

    /**
     *  根据ticke 获取会员电子券信息
     * @return
     */
    @RequestMapping(value = "/Coupons",method = RequestMethod.GET)
    public BaseResultDto getCoupons(
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        RodimusLoginBaseParamDto rodimusLoginBaseParamDto = new RodimusLoginBaseParamDto();
        QueryResult<PmsCouponDto> pmsMemberCouponsDtoQueryResult = memberApiFacadeService.getPMSmemberCoupons(rodimusLoginBaseParamDto);
       res.setQueryResult(pmsMemberCouponsDtoQueryResult);
        res.setResultCode(0);
        return res;
    }


    /**
     *  根据ticke 获取会员销售员券信息
     * @return
     */
    @RequestMapping(value = "/Salesmans",method = RequestMethod.GET)
    public BaseResultDto getSalesmans(
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        RodimusLoginBaseParamDto rodimusLoginBaseParamDto = new RodimusLoginBaseParamDto();
        res.setResultCode(0);
        res.setQueryResult(memberApiFacadeService.getSalesmans(rodimusLoginBaseParamDto) );
        return res;
    }


    /**
     *  根据ticke 获取会员销售员券信息
     * @return
     */
    @RequestMapping(value = "/UsableCoupons",method = RequestMethod.GET)
    public BaseResultDto getUsableCoupons(
            @RequestParam (value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam (value = "arrtime" ,required = false) String arrtime,
            @RequestParam (value = "checkInDatetime" ,required = false) String checkInDatetime,
            @RequestParam (value = "rmtype" ,required = false) String rmtype,
            @RequestParam (value = "rateCode" ,required = false) String rateCode,
            @RequestParam(value = "amount", required = false) BigDecimal amount,
            @RequestParam (value = "l2RMemberNo" ,required = false) String l2RMemberNo
    ) throws Exception {
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);

        UsableCouopnsApiParamDto usableCouopnsApiParamDto = new UsableCouopnsApiParamDto();
        usableCouopnsApiParamDto.setLhotelCode(lhotelCode );
        usableCouopnsApiParamDto.setArr(arrtime );
        if(StringUtil.isNotBlank(checkInDatetime)){
            usableCouopnsApiParamDto.setArr(checkInDatetime);
        }
        usableCouopnsApiParamDto.setRmtype( rmtype);
        usableCouopnsApiParamDto.setRateCode( rateCode);
        usableCouopnsApiParamDto.setAmount(amount);
        res.setQueryResult(memberApiFacadeService.getUsableCoupons(usableCouopnsApiParamDto ));
        return res;
    }

    @RequestMapping(value = "/syncCurrentUserLevel",method = RequestMethod.PUT)
    public BaseResultDto levelSync() throws Exception {
        memberApiFacadeService.syncCurrentMemberLevel(new BaseL2rParamDto());
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }

    @RequestMapping(value = "/modifyCurrentUserMemberName" , method = RequestMethod.PUT)
    public BaseResultDto modifyCurrentUserMemberName(@RequestBody ModifyCurrentUserMemberNameParamDto paramDto) throws Exception {
        memberApiFacadeService.modifyCurrentUserMemberName(paramDto);
        BaseResultDto res = new BaseResultDto();
        res.setResultCode(0);
        return res;
    }
}
